In article <74**************************@posting.google.com >,
bi*********@hotmail.com (Bill S.) writes:
I have a form that is generated by an ASP page,
and I want to write a client-side function in
JavaScript to clear all the checkboxes in a form.
The problem is that the number of items on the form
depends on records in a database, and all the checkboxes
have the same name, ie:
The fact that they all have the same name actually makes it easier. See below.
<form name="myForm" method="post" action="MyPage.asp">
.
. variable number of input fields
.
<input type="checkbox" value="2" name="memberOf" checked>
<input type="checkbox" value="1" name="memberOf" checked>
.
. repeats variable number of times
.
Is there another way to do this in JavaScript?
I can have the server side create client-side variables
that would tell me the form element number for the first
checkbox and the number of checkboxes if I have to, but
I would prefer something cleaner.
function clearCheckboxes(){
for (i=0;i<document.myForm.elements.length;i++)
{
if (document.myForm.elements[i].name == 'memberOf')
{
document.myForm.elements[i].checked = false;
}
}
}
<input type="button" value="Clear Member Boxes"
onclick="clearCheckboxes()" />
--
Randy